#include "rdiskio.h"
#include "IFDInterface.h"
#include "IFD.h"



inline static _drvTool* _GetDrvTool()
{
	_drvTool* address;
	__asm__ __volatile__(
	"SVC 0x01;"
	"MOV %0, r0;"
	:"=r"(address)
	:
	:
	);
	return address;
}

FRESULT disk_initialize (void** object,const char* path,DWORD mode)
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[3];
	argv[0] = object;
	argv[1] = path;
	argv[2] = mode;
	return drvt->FileOperate(object,FILE_OPEN,argv,3);
}

FRESULT disk_status (const char* path,_info* info)
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[2];
	char* prepath;
	argv[0] = path;
	argv[1] = info;
	void** object;
	drvt->GetFileSysHandle(path,&object,&prepath);
	return drvt->FileOperate(object,FILE_STAT,argv,2);
}

FRESULT disk_read (void** object, char* path, DWORD size, DWORD offset)	//i write it wrong, path == buff
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[4];
	argv[0] = object;
	argv[1] = path;
	argv[2] = size;
	argv[3] = offset;
	return drvt->FileOperate(object,FILE_READ,argv,4);
}

FRESULT disk_write (void** object, const char* path, DWORD size,DWORD offset)//i write it wrong, path == buff
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[2];
	argv[0] = object;
	argv[1] = path;
	argv[2] = size;
	argv[3] = offset;
	return drvt->FileOperate(object,FILE_WRITE,argv,4);
}

FRESULT disk_ioctl (void** object, BYTE code, void* buff)
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[3];
	argv[0] = object;
	argv[1] = code;
	argv[2] = buff;
	return drvt->FileOperate(object,FILE_IOCTL,argv,3);
}

FRESULT disk_uninit (void** object)
{
	_drvTool* drvt = GetDrvTool();
	unsigned int argv[1];
	argv[0] = object;
	return drvt->FileOperate(object,FILE_CLOSE,argv,3);
}
